home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12521 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Sort Function
  5. Date: Mon, 01 Apr 96 14:17:44 GMT
  6. Organization: none
  7. Message-ID: <828368264snz@genesis.demon.co.uk>
  8. References: <4jmq99$cqi@freenet-news.carleton.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4jmq99$cqi@freenet-news.carleton.ca>
  15.            aq436@FreeNet.Carleton.CA "Jerry Boyd" writes:
  16.  
  17. >How would I WRITE a function (called sort3) that would 
  18. >sort three integers (in assending order) by using pointers
  19. >and NOT arrays?
  20.  
  21. Define your function interface i.e. in what form you want the data passed
  22. to the function and in what form you want the results. For example if
  23. you want to pass 3 pointer arguments you could write something along the
  24. lines of:
  25.  
  26. void sort3(int *p1, int *p2, int *p3)
  27.  
  28. {
  29.     if (*p1 > *p2)
  30.         swapint(p1, p2);
  31.  
  32.     if (*p2 > *p3) {
  33.         swapint(p2, p3);
  34.  
  35.     if (*p1 > *p2)
  36.             swapint(p1, p2);
  37.     }
  38. }
  39.  
  40. where I leave it up to you to implement swapint().
  41.  
  42. -- 
  43. -----------------------------------------
  44. Lawrence Kirby | fred@genesis.demon.co.uk
  45. Wilts, England | 70734.126@compuserve.com
  46. -----------------------------------------
  47.